package com.yitong.profile.dao.impl;

import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.yitong.base.dao.api.ReadDao;
import com.yitong.base.dao.api.WriteDao;
import com.yitong.base.domain.DwzResult;
import com.yitong.base.domain.Page;
import com.yitong.profile.dao.api.CompanyDao;
import com.yitong.profile.domain.Company;

@Component
public class CompanyDaoImpl implements CompanyDao {

	@Inject
	private ReadDao readDao;

	@Inject
	private WriteDao writeDao;

	private DwzResult dwzResult = new DwzResult();

	@Override
	public Page<?> listCompanyWithPage(Map<String, Object> param, int pageNum, int pageSize) throws Exception {
		Page<?> page = null;
		page = readDao.findPage1("company.listCompanyWithPage", "company.count", param, pageNum, pageSize);
		return page;
	}

	@Override
	public Company showCompanyById(Map<String, Object> param) throws Exception {
		Company company = null;
		company = (Company) readDao.load("company.showCompanyById", param);
		return company;
	}

	@Override
	public DwzResult update(Map<String, Object> param) throws Exception {
		writeDao.update("company.update", param);
		this.dwzResult.setNavTabId("company_list");
		this.dwzResult.setStatusCode("200");
		this.dwzResult.setMessage("更新信息成功！");
		this.dwzResult.setCallbackType("closeCurrent");
		this.dwzResult.setForwardUrl("");
		return dwzResult;
	}

	@Override
	public DwzResult delete(Map<String, Object> param) throws Exception {
		writeDao.delete("company.delete", param);
		this.dwzResult.setNavTabId("company_list");
		this.dwzResult.setStatusCode("200");
		this.dwzResult.setMessage("删除信息成功！");
		this.dwzResult.setCallbackType("");
		this.dwzResult.setForwardUrl("");
		return dwzResult;
	}

	@Override
	public DwzResult insert(Map<String, Object> param) throws Exception {
		writeDao.insert("company.insertSelective", param);
		this.dwzResult.setNavTabId("company_list");
		this.dwzResult.setStatusCode("200");
		this.dwzResult.setMessage("保存信息成功！");
		this.dwzResult.setCallbackType("closeCurrent");
		this.dwzResult.setForwardUrl("");
		return dwzResult;
	}

}
